<template>
	<!-- 人声模型列表 -->
	<view>
		<view class="list">
			<z-paging ref="paging" v-model="list" @query="queryList" :fixed="false" :auto-clean-list-when-reload="false"
				:auto="true" :paging-style="{ height:'100%' }" :show-refresher-when-reload="true"
				:default-page-size="10" :hide-empty-view="true">
				<view class="box1">
					<view class="box_item1" @click="change(item.clipTaskId)"
						:class="item.clipTaskId===clipTaskId?'act':''" v-for="(item,index) in list" :key="index">
						<view class="zl-flex zl-row-between">
							<view class="zl-flex">
								<image src="/static/clone/voiceIcon.png" mode="" class="play"
									style="width: 80rpx;height: 80rpx;">
								</image>
								<view class="zl-flex-col zl-m-l-18">
									<view class="zl-font-30 zl-color-000"> 主播华华 </view>
									<view class="zl-font-20 zl-color-999 zl-m-t-8" style="opacity: 0.6;"> 2024-09-28
										11:17:11 </view>
								</view>
								<image v-show="item.clipTaskId===clipTaskId"
									style="position: absolute;bottom: -2rpx;right: -2rpx;width: 50rpx;"
									src="/static/clone/choosed.png" mode="widthFix"></image>
							</view>
							<view class="zl-flex">
								<view class="download" v-if="playIng&&playId===item.userFileId" @click="stop">
									<image src="/static/work/stop.png" mode=""
										style="width: 25rpx;height: 25rpx;margin-right: 6rpx;"></image>
									暂停
								</view>
								<view v-else class="download">
									<image @click="listen(item)" src="/static/work/listen.png" mode=""
										style="width: 25rpx;height: 25rpx;margin-right: 6rpx;"></image> 试听
								</view>
								<view class="edit">
									删除
								</view>
							</view>
						</view>
					</view>
					<view v-if="list.length<=0" class=" zl-flex-col zl-col-center"
						style="width: 690rpx;margin-top: 50%;">
						<image src="/static/work/empty.png" mode="widthFix" style="width: 230rpx;margin-bottom: 48rpx;">
						</image>
						<text class="zl-font-30 zl-color-666">空空如也，您还没有创建哦~</text>
					</view>
				</view>
			</z-paging>
		</view>
		<view class="footer zl-flex zl-row-center">
			<view class="btn" @click="sure()"> 确定 </view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				clipTaskId: 1,
				playurl: '',
				playIng: false,
				innerAudioContext: null,
				playId: ''
			};
		},
		onLoad() {},
		methods: {
			change(id) {
				this.clipTaskId = id;
			},
			queryList(page, limit) {
				this.api.clip.getcliptasklist({
					page: page,
					limit: limit,
					status: 0,
					target: 3
				}).then(res => {
					console.log(res);
					this.$refs.paging.complete([{
						clipTaskId: 1
					}, {
						clipTaskId: 2
					}]);
					// this.$refs.paging.complete(res.data.list)
				}).catch(err => {
					this.$refs.paging.complete(false);
					this.$util.msg('请检查网络连接！');
				})
			},
			sure() {
				uni.$emit('chooseclipTaskId', this.clipTaskId);
				uni.navigateBack()
			},
			listen(item) {
				this.api.music.getmusic({
					musicId: item.musicId
				}).then(res => {
					if (res.code === 0) {
						this.playurl = res.data.url;
						this.playIng = true;
						this.playId = item.userFileId
						this.play();
					} else {
						this.$util.msg(res.msg);
					}
				}).catch(err => {
					this.$util.msg('请检查网络连接！');
				})
			},
			play() {
				if (this.innerAudioContext) {
					this.innerAudioContext.stop();
				}
				this.innerAudioContext = uni.createInnerAudioContext();
				this.innerAudioContext.src = this.playurl;
				this.innerAudioContext.play();
				this.innerAudioContext.onEnded(() => {
					this.playIng = false;
				});
			},
			// 暂停
			stop() {
				if (this.innerAudioContext) {
					this.innerAudioContext.stop();
				}
				this.playurl = '';
				this.playIng = false;
			}
		}
	}
</script>
<style lang="scss" scoped>
	.list {
		margin: 0 30rpx;
		width: 750rpx;
		height: calc(100vh - 190rpx);
		background-color: #EDF0F4;

		.box {
			display: flex;
			flex-direction: row;
			gap: 30rpx;
			flex-wrap: wrap;

			.box_item {
				width: 330rpx;

				.video {
					width: 100%;
					height: 486rpx;
				}

				.content {
					background-color: #fff;
					padding: 24rpx 30rpx;
					border-radius: 0rpx 0rpx 10rpx 10rpx;
				}
			}
		}

		.box1 {
			width: 690rpx;
			border-radius: 20rpx;

			.act {
				border: 5rpx solid #EB5E00 !important;
			}

			.box_item1 {
				padding: 40rpx 30rpx;
				// height: 160rpx;
				margin-top: 30rpx;
				display: flex;
				flex-direction: column;
				background: #FFFFFF;
				border-radius: 20rpx;
				border: 5rpx solid #fff;
				position: relative;

				.line {
					margin-top: 40rpx;
					width: 633rpx;
					height: 1rpx;
					border: 1rpx solid #979797;
					opacity: 0.2;
				}

				.content {
					margin-top: 30rpx;
					font-size: 24rpx;
					color: #999999;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}
		}

		.download {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 121rpx;
			height: 56rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			border: 1rpx solid #000000;
			font-weight: 400;
			font-size: 24rpx;
			color: #000000;
		}

		.edit {
			margin-left: 24rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 85rpx;
			height: 56rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			border: 1rpx solid #000000;
			font-weight: 400;
			font-size: 24rpx;
			color: #000000;
		}
	}

	.btn {
		background-color: #FFFFFF;
		margin-bottom: 30rpx;
		height: 120rpx;
		border-radius: 10rpx;
		color: #131415;
		font-weight: 500;
	}

	.footer {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 750rpx;
		height: 190rpx;
		background: #FFFFFF;

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 690rpx;
			height: 110rpx;
			background: linear-gradient(90deg, #EB7A00 0%, #EB5E00 100%);
			box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(66, 106, 171, 0.29);
			border-radius: 20rpx;
			font-size: 36rpx;
			color: #F9F9F9;
		}
	}
</style>